/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package prim;

import base.JGrafo;
import base.Vertice;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author diego
 */
public class Main {
    public static void main(String args[]) {
        
        // GRAFO 1
        
        HashMap<AbstractMap.SimpleEntry<Vertice, Vertice>, Integer> weights = new HashMap<>();
        
        ArrayList<Vertice> vertices = new ArrayList<>();
        vertices.add(new Vertice("A"));
        vertices.add(new Vertice("B"));
        vertices.add(new Vertice("C"));
        vertices.add(new Vertice("D"));
        vertices.add(new Vertice("E"));
        vertices.add(new Vertice("F"));
        vertices.add(new Vertice("G"));
        vertices.add(new Vertice("H"));
        vertices.add(new Vertice("K"));
        JGrafo g = new JGrafo(vertices);
        
        // A
        
        g.add_edge(vertices.get(0), vertices.get(1));
        g.add_edge(vertices.get(1), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(1)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(0)), 5);
        
        g.add_edge(vertices.get(0), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(6)), 10);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(0)), 10);
        
        g.add_edge(vertices.get(0), vertices.get(7));
        g.add_edge(vertices.get(7), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(7)), 10);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(7), vertices.get(0)), 10);
        
        g.add_edge(vertices.get(0), vertices.get(4));
        g.add_edge(vertices.get(4), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(4)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(0)), 5);
        
        // B
        
        g.add_edge(vertices.get(1), vertices.get(5));
        g.add_edge(vertices.get(5), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(5)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(5), vertices.get(1)), 5);
        
        g.add_edge(vertices.get(1), vertices.get(7));
        g.add_edge(vertices.get(7), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(7)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(7), vertices.get(1)), 5);
        
        g.add_edge(vertices.get(1), vertices.get(8));
        g.add_edge(vertices.get(8), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(8)), 10);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(8), vertices.get(1)), 10);
        
        // C
        
        g.add_edge(vertices.get(2), vertices.get(3));
        g.add_edge(vertices.get(3), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(3)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(2)), 5);
        
        g.add_edge(vertices.get(2), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(6)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(2)), 5);
        
        g.add_edge(vertices.get(2), vertices.get(4));
        g.add_edge(vertices.get(4), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(4)), 10);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(2)), 10);
        
        // D
        
        g.add_edge(vertices.get(3), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(6)), 10);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(3)), 10);
        
        g.add_edge(vertices.get(3), vertices.get(4));
        g.add_edge(vertices.get(4), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(4)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(3)), 5);
        
        // E
        
        g.add_edge(vertices.get(4), vertices.get(8));
        g.add_edge(vertices.get(8), vertices.get(4));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(8)), 10);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(8), vertices.get(4)), 10);
        
        // F
        
        g.add_edge(vertices.get(5), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(5));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(5), vertices.get(6)), 15);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(5)), 15);
        
        // H
        
        g.add_edge(vertices.get(7), vertices.get(8));
        g.add_edge(vertices.get(8), vertices.get(7));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(7), vertices.get(8)), 20);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(8), vertices.get(7)), 20);
        
        ArrayList<AbstractMap.SimpleEntry<Vertice, Vertice>> mst_prim = PRIM.mst_prim(g, weights, vertices.get(0));
        
        System.out.println("Vértices da AGM 1: ");
        
        int peso = 0;
        for (AbstractMap.SimpleEntry<Vertice, Vertice> pair : mst_prim) {
            System.out.println(pair.getKey().name+", "+pair.getValue().name);
            peso += weights.get(pair);
        }
        
        System.out.println("Peso da AGM: "+peso);
        
        System.out.println();
        
        // GRAFO 2:
        
        weights = new HashMap<>();
        
        vertices = new ArrayList<>();
        vertices.add(new Vertice("1"));
        vertices.add(new Vertice("2"));
        vertices.add(new Vertice("3"));
        vertices.add(new Vertice("4"));
        vertices.add(new Vertice("5"));
        vertices.add(new Vertice("6"));
        vertices.add(new Vertice("7"));
        vertices.add(new Vertice("8"));
        g = new JGrafo(vertices);
        
        // 1
        
        g.add_edge(vertices.get(0), vertices.get(1));
        g.add_edge(vertices.get(1), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(1)), 8);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(0)), 8);
        
        g.add_edge(vertices.get(0), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(6)), 9);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(0)), 9);
        
        g.add_edge(vertices.get(0), vertices.get(2));
        g.add_edge(vertices.get(2), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(2)), 2);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(0)), 2);
        
        // 2
        
        g.add_edge(vertices.get(1), vertices.get(2));
        g.add_edge(vertices.get(2), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(2)), 3);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(1)), 3);
        
        g.add_edge(vertices.get(1), vertices.get(3));
        g.add_edge(vertices.get(3), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(3)), 2);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(1)), 2);
        
        g.add_edge(vertices.get(1), vertices.get(4));
        g.add_edge(vertices.get(4), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(4)), 7);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(1)), 7);
        
        g.add_edge(vertices.get(1), vertices.get(5));
        g.add_edge(vertices.get(5), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(5)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(5), vertices.get(1)), 5);
        
        g.add_edge(vertices.get(1), vertices.get(7));
        g.add_edge(vertices.get(7), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(7)), 6);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(7), vertices.get(1)), 6);
        
        // 3
        
        g.add_edge(vertices.get(2), vertices.get(3));
        g.add_edge(vertices.get(3), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(3)), 9);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(2)), 9);
        
        g.add_edge(vertices.get(2), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(6)), 6);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(2)), 6);    
        
        // 4
        
        g.add_edge(vertices.get(3), vertices.get(4));
        g.add_edge(vertices.get(4), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(4)), 6);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(3)), 6);
        
        g.add_edge(vertices.get(3), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(6)), 2);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(3)), 2);
        
        // 5
        
        g.add_edge(vertices.get(4), vertices.get(5));
        g.add_edge(vertices.get(5), vertices.get(4));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(5)), 5);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(5), vertices.get(4)), 5);
        
        g.add_edge(vertices.get(4), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(4));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(6)), 4);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(4)), 4);
        
        // 6
        
        g.add_edge(vertices.get(5), vertices.get(7));
        g.add_edge(vertices.get(7), vertices.get(5));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(5), vertices.get(7)), 4);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(7), vertices.get(5)), 4);
        
        g.add_edge(vertices.get(5), vertices.get(6));
        g.add_edge(vertices.get(6), vertices.get(5));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(5), vertices.get(6)), 6);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(5)), 6);
        
        // 7
        
        g.add_edge(vertices.get(6), vertices.get(7));
        g.add_edge(vertices.get(7), vertices.get(6));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(6), vertices.get(7)), 3);
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(7), vertices.get(6)), 3);
        
        mst_prim = PRIM.mst_prim(g, weights, vertices.get(0));
        
        System.out.println("Vértices da AGM 2: ");
        
        peso = 0;
        for (AbstractMap.SimpleEntry<Vertice, Vertice> pair : mst_prim) {
            System.out.println(pair.getKey().name+", "+pair.getValue().name);
            peso += weights.get(pair);
        }
        
        System.out.println("Peso da AGM: "+peso);
        
    }

}
